import $ from 'jquery';

export function getTitle () {
  return {
    subtext: '',
    left: 'left',
    top: 'top',
    textStyle: Font(16),
    subtextStyle: {
      color: '#aaa',
      fontFamily: 'Sans-serif',
      fontSize: 12
    }
  };
}

export function getGrid () {
  return $.extend({
    left: '10%',
    top: 60,
    right: '10%',
    bottom: 60,
    containLabel: false,
    backgroundColor: 'transparent',
    borderColor: '#ccc',
    borderWidth: 1
  }, Shadow());
}

export function getLabel () {
  return $.extend(Label(), LabelExtra());
}

export function VisualMap () {
  return {
    type: 'continuous',
    min: 0,
    max: 100,
    // range: [],
    calculable: true,
    realtime: true,
    inverse: false,
    precision: 0,
    itemWidth: 20,
    itemHeight: 140,
    align: 'left',
    text: ['', ''],
    textGap: 10,
    show: true,
    dimension: 0,
    seriesIndex: 0,
    hoverLink: true,
    inRange: {
      color: ['#edfbfb', '#b7d6f3', '#40a9ed']
    },
    left: 0,
    top: 'bottom',
    right: '',
    bottom: 10,
    orient: 'vertical',
    padding: 5,
    backgroundColor: 'rgba(0,0,0,0)',
    borderColor: '#ccc',
    borderWidth: 0, 
    textStyle: Font(12)
  };
}

export function ItemStyle () {
  return $.extend({
    color: '',
    borderColor: '#000',
    borderWidth: 0,
    borderType: 'solid'
  }, Shadow());
}

function LabelExtra () {
  return {
    rotate: 0,
    distance: 5,
    offset: [0, 0]
  };
}

function Label (position) {
  return $.extend({
    show: false,
    position: position || 'top',
    formatter: '{c}'
  }, Font(null, null), {
    // lineHeight: '50',
    backgroundColor: 'transparent',
    borderColor: 'transparent',
    borderWidth: 0,
    borderRadius: 0
  });
}

function Font (fontSize, align) {
  return $.extend({
    color: '#333',
    fontFamily: 'Sans-serif',
    fontSize: fontSize || 12,
    fontWeight: 'normal',
    align: align || 'center',
    verticalAlign: 'middle',
    textBorderColor: 'transparent',
    textBorderWidth: 1
  }, Shadow());
}

export function Shadow () {
  return {
    shadowColor: 'transparent',
    shadowBlur: 0,
    shadowOffsetX: 0,
    shadowOffsetY: 0
  };
}

export function LineStyle () {
  return $.extend({
    color: '',
    width: 1,
    type: 'solid',
    opacity: 1
  }, Shadow());
}

function AxisLabel (index) {
  return $.extend({
    show: true,
    interval: 'auto',
    inside: false,
    rotate: 0,
    margin: 8,
    formatter: null
  }, Font(12, index ? 'center' : 'right'));
  // 注：Font.align 横轴center，纵轴right
}

export function getAxis (index) {
  return {
    name: '',
    show: true,
    nameRotate: null,
    nameGap: 15,
    inverse: false,
    nameLocation: 'end',
    min: null,
    max: null, // function (v) { return v.max + 0.2 * v.max; },
    axisLine: {
      show: true,
      symbol: ['none', 'none'],
      symbolSize: [10, 15],
      lineStyle: LineStyle()
    },
    axisTick: {
      show: true,
      interval: 'auto',
      inside: false,
      length: 5,
      lineStyle: LineStyle()
    },
    axisLabel: AxisLabel(index),
    splitLine: {
      show: true,
      interval: 'auto',
      lineStyle: LineStyle()
    }
  };
}
